package com.event.management.backend.controller;

import com.event.management.backend.util.CacheUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 缓存控制器
 * 提供手动清除缓存的接口
 */
@RestController
@RequestMapping("/api/system/cache")
@Api(tags = "缓存管理接口")
@Slf4j
public class CacheController {
    
    @Autowired
    private CacheUtil cacheUtil;
    
    /**
     * 清除所有缓存
     */
    @DeleteMapping("/clear")
    @ApiOperation("清除所有缓存")
    public Map<String, Object> clearAllCache() {
        log.info("手动触发清除所有缓存");
        Map<String, Object> result = new HashMap<>();
        
        try {
            cacheUtil.clearAllCache();
            result.put("success", true);
            result.put("message", "缓存清除成功");
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "缓存清除失败: " + e.getMessage());
        }
        
        return result;
    }
} 